const UserModel = require('../models/User')

const index = async (req, res) => {
  res.send({
    msg: '管理员',
    status: 0
  })
}

const usersList = async (req,res) => {
  let result = await UserModel.usersList()
  if(result) {
    res.send({
      msg: "请求所有用户信息成功",
      status: 0,
      data: {
        usersList: result
      }
    })
  }else {
    res.send({
      msg: '请求所有用户信息失败',
      status: -1
    })
  }
}

const updateFreeze = async (req,res) => {
  let {email, isFreeze} = req.body
  let result = await UserModel.updateFreeze(email, isFreeze)
  if(result) {
    res.send({
      msg: '账号冻结成功',
      status: 0
    })
  }else{
    res.send({
      msg: '账号冻结失败',
      status: -1
    })
  }
}

const deleteUser = async (req,res) => {
  let {email} = req.body
  let result = await UserModel.deleteUser(email)
  console.log(req.body);
  if(result) {
    res.send({
      msg: '用户删除成功',
      status: 0
    })
  }else {
    res.send({
      msg: '用户删除失败',
      status: -1
    })
  }
}

module.exports = {
  index, usersList,updateFreeze,deleteUser,
}


